<template>
  <el-form-item
    :label="label"
    :label-width="labelWidth"
    :prop="props.data.field"
    :required="props.data.required"
    :rules="props.data.rules"
  >
    <el-input
      v-model="val"
      :style="{ width: `${props.data.compWidth || 100}%` }"
      type="textarea"
      show-word-limit
      :rows="props.data.rows"
      :placeholder="props.data.placeholder"
      :maxlength="props.data.length"
      :readonly="props.data.readonly"
      :disabled="props.data.disabled"
    >
    </el-input>
  </el-form-item>
</template>

<script setup lang="ts">
import { onMounted } from 'vue'
import { ElFormItem, ElInput } from 'element-plus'
import { useProps, useValue } from '../../common-props/hooks'
import type { FormMode } from '@/typings'

const props = defineProps<{ data: Record<string, any>; form: Record<string, any>; mode: FormMode }>()
const emits = defineEmits(['valueChange'])

const { label, labelWidth } = useProps(props)
const { val } = useValue(props, emits)

onMounted(() => {
  if (props.mode === 'approve') {
    val.value = ''
    emits('valueChange', { name: props.data.field, value: val.value })
  }
})
</script>

<style lang="scss" scoped></style>
